#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
class Solution
{
public:
    TreeNode *dfs(TreeNode *t1, TreeNode *t2)
    {
        TreeNode *t = NULL, *lchild = NULL, *rchild = NULL;
        if (t1 == NULL || t2 == NULL)
        {
            if (t1 == NULL && t2 == NULL)
                return NULL;
            if (t1 != NULL)
            {
                t = new TreeNode(t1->val);
                lchild = dfs(t1->left, t2);
                rchild = dfs(t1->right, t2);
            }
            else
            {
                t = new TreeNode(t2->val);
                lchild = dfs(t1, t2->left);
                rchild = dfs(t1, t2->right);
            }
        }
        else
        {
            t = new TreeNode(t1->val + t2->val);
            lchild = dfs(t1->left, t2->left);
            rchild = dfs(t1->right, t2->right);
        }
        t->left = lchild;
        t->right = rchild;
        return t;
    }
    TreeNode *mergeTrees(TreeNode *t1, TreeNode *t2)
    {
        TreeNode *t = NULL;
        t = dfs(t1, t2);
        return t;
    }
};